home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / Dev / Amiga-E / E_v3.2a / Src / Dos / readtext.e < prev    next >
Text File  |  1992-09-02  |  637b  |  28 lines

  1. /* read a text file example. note that the program has no
  2.    hardcoded limit on the lenght of the file */
  3.  
  4. CONST MAXLINELEN=1000
  5.  
  6. PROC main()
  7.   DEF fh,buf[MAXLINELEN]:ARRAY,n=0,last=NIL,s,first=NIL
  8.   IF fh:=Open(arg,OLDFILE)
  9.     WHILE Fgets(fh,buf,MAXLINELEN)
  10.       IF (s:=String(StrLen(buf)))=NIL THEN Raise("MEM")
  11.       StrCopy(s,buf,ALL)
  12.       IF last THEN Link(last,s) ELSE first:=s
  13.       last:=s
  14.       INC n
  15.     ENDWHILE
  16.     Close(fh)
  17.     WriteF('FILE: "\s", \d lines.\n\n',arg,n)
  18.     s:=first
  19.     WHILE s
  20.       PutStr(s)
  21.       s:=Next(s)
  22.     ENDWHILE
  23.     DisposeLink(first)
  24.   ELSE
  25.     WriteF('no file: "\s"\n',arg)
  26.   ENDIF
  27. ENDPROC
  28.